

using System.Numerics;

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_Length_RT : RT_Node
    {
        public RT_SingleValuePort InputVector_RT;

        public RT_SingleValuePort Length_RT;

        public Node_Length_RT(Node_Length sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            InputVector_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.InputVector, this);

            Length_RT = new RT_SingleValuePort(EPortIOType.Output, sourceData.Length, this);
            Length_RT.OnGetValue = GetLength;
        }

        public AValue GetLength(DAG_Executor executor)
        {
            var inVec = InputVector_RT.GetValue(executor);
            var vecType = inVec.ValueType;
            if (vecType == AValue.EValueType.Vector2)
            {
                Vector2 inVec2 = inVec.ToVector2().Item2;
                float result = inVec2.Length();
                Length_RT.SourceValue.SetScalar(result);
            }
            else if (vecType == AValue.EValueType.Vector3)
            {
                Vector3 inVec3 = inVec.ToVector3().Item2;
                float result = inVec3.Length();
                Length_RT.SourceValue.SetScalar(result);
            }
            return Length_RT.SourceValue;
        }
    }
}